#include "qsamplehswidget.h"
#include <QDebug>


const QString sw_type = "onerow";
const QString sw_name = "[Ex] [Qt] HS Widget";
const QString sw_id = "0xE59C7E13"; //can be any unique string

const QString sw_image ("image1");
const QString sw_text ("text1");

QSampleHSWidget::QSampleHSWidget(QObject *parent) :
    QObject(parent), counter(0)
{
    widget = new QHSWidget(sw_type, sw_name, sw_id, this);
    connect(widget, SIGNAL(handleEvent(QHSWidget*, QHSEvent)), this, SLOT(handleEvent(QHSWidget*, QHSEvent) ));
    connect(widget, SIGNAL(handleItemEvent(QHSWidget*, QString, QHSItemEvent)), this, SLOT(handleItemEvent(QHSWidget*, QString, QHSItemEvent)));
}

void QSampleHSWidget::RegisterWidget()
{
    widget->RegisterWidget();

}

void QSampleHSWidget::PublishWidget()
{
    widget->PublishWidget();
}


void QSampleHSWidget::RemoveWidget()
{
    widget->RemoveWidget();
}

void QSampleHSWidget::handleEvent( QHSWidget* /*aSender*/, QHSEvent aEvent )
{
    switch(aEvent)
                    {
                    case QHSWidget::EActivate:
                    case QHSWidget::EResume:
                            {
                            ChangeWidgetValues();
                            PublishWidget();
                            }
                            break;
                    default:
                            break;
                    }

}

void QSampleHSWidget::handleItemEvent( QHSWidget* /*aSender*/, QString aTemplateItemName,
    QHSItemEvent aEvent)
{
    if(aTemplateItemName.compare(sw_image)==0)
                    {
                    ChangeWidgetValues();
                    PublishWidget();
                    }
            else
                    {
                        emit BringMeToForeground();
                    }
}

void QSampleHSWidget::ChangeWidgetValues()
{
    QString buf1;
    QString buf2;
    if( !( counter % 2 ) )
    {
        buf1 = QString("c:\\data\\Images\\Pictures\\QtSunny2.JPG");
        buf2 = QString("First text: Good morning");
    } else {
        buf1 = QString("c:\\data\\Images\\Pictures\\QtSunny.JPG");
        buf2 = QString("Second text: Good afternoon");
    }

    widget->SetItem(sw_image, buf1);
    widget->SetItem(sw_text, buf2);

    counter++;
}
